import { _decorator, Label, tween, Tween, UITransform } from 'cc';
import { BasePopUp } from '../../../frame/component/ui.pop-up';
import type { Popup } from '../page/pop-up';
const { ccclass, property } = _decorator;

@ccclass('ppDefeat')
export class ppDefeat extends BasePopUp<typeof Popup, null> {
	protected default_return: null;

	private lbl_round: Label;
	private ui_light: UITransform;

	protected initAfterOnLoad(){
		this.init();
		this.initUIStatus();
	}

	public onShow(round: number){
		BasePopUp.jelly_enter(this.node);

		this.lbl_round.string = 'Level ' + round;

		Tween.stopAllByTarget(this.ui_light.node);

		tween(this.ui_light.node) .set({angle: 0}) .to(5, {angle: 360}) .union().repeatForever().start();

		mtec.delay(3, ()=>BasePopUp.jelly_leave(this.node))
		.then(()=>{
			Tween.stopAllByTarget(this.ui_light.node);
			this.ui_light.node.angle = 0;
			this.close(null);
		});
	}

	private init(){
		this.lbl_round = this.node.getChildByName('lbl-round').getComponent(Label);
		this.ui_light = this.node.getChildByName('light').getComponent(UITransform);
	}

	private initUIStatus(){
		this.node.getChildByName('lbl-head').getComponent(Label).string = 'Failed challenge';
	}
}

